<template>
  <div>
    <h1>BMIApp</h1>
    <BMIFormComponent
      :is-show-status="isShowStatus"
      :current-data="currentData"
      @emit-bmi="getEmitBmi"
    />
    <BMIStatusComponent :status="currentData.status"/>
    <BMiDEL :list="list.data" @delItem="delItem"></BMiDEL>

  </div>

</template>

<script>
import BMIFormComponent from "./components/bmi/BMIFormComponent";
import BMIStatusComponent from "./components/bmi/BMIStatusComponent";
import http from 'axios'
import BMiDEL from "./components/bmi/BMiDEL";

export default {
  name: "BMIApp",
  components: {
    BMiDEL,
    BMIFormComponent,
    BMIStatusComponent
  },
  data() {
    return {
      currentData: {},
      isShowStatus: false,
      list:[]
    }
  },
  created(){
      this.getList()
  },

  methods: {
    getEmitBmi(data) {
      http({
        url: 'https://veihwwnelcwq.leanapp.cn/bmi',
        method: 'POST',
        data: data
      }).then(res => {
        this.isShowStatus = true
        this.currentData = res.data.data
        this.getList()
      })
    },

    getList() {
      http({
        url: 'https://veihwwnelcwq.leanapp.cn/bmi'
      }).then(res => {
        this.list = res.data
      })
    },


    delItem(id) {
      if (confirm('删除？')){
        http({
          url:'https://veihwwnelcwq.leanapp.cn/bmi',
          method:'DELETE',
          data:{
            id:id
          }
        }).then(res => {
            console.log(res)
            this.getList()
        })
      }
    },

  }
}
</script>

<style lang="less">

div {
  background-color: #ff55b3;
}



</style>